﻿using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace ProjectYANApi.Function
{
    public class myCommon
    {
        public const string uniChars =
          "àáảãạâầấẩẫậăằắẳẵặèéẻẽẹêềếểễệđìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵÀÁẢÃẠÂẦẤẨẪẬĂẰẮẲẴẶÈÉẺẼẸÊỀẾỂỄỆĐÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸỴÂĂĐÔƠƯ";
        public const string vnClass =
    "aaaaaaaaaaaaaaaaaeeeeeeeeeeediiiiiooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAAEEEEEEEEEEEDIIIOOOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYAADOOU";

        public static string GetDateDiff(DateTime dDate)
        {
            DateTime dNow = DateTime.Now;
            string strResult = string.Empty;
            if (DateTime.Compare(dNow, dDate) > 0)
            {
                TimeSpan ts = dNow.Subtract(dDate);

                if (ts.Days >= 1)
                {
                    strResult = dDate.ToString("HH:mm | dd/MM/yyyy");
                }
                else if (ts.Days == 0 && ts.Hours > 0)
                {
                    strResult = ts.Hours.ToString() + " giờ trước";
                }
                else if (ts.Days == 0 && ts.Hours == 0 && ts.Minutes > 0)
                {
                    strResult = ts.Minutes.ToString() + " phút trước";
                }
            }
            return strResult;
        }

        public static string UnicodeToKoDau(string s)
        {
            string retVal = "";

            if (s == null)
                return retVal;

            int pos;
            s = s.Trim();

            for (int i = 0; i < s.Length; i++)
            {
                pos = uniChars.IndexOf(s[i].ToString());
                if (pos >= 0)
                    retVal += vnClass[pos];
                else
                    retVal += s[i];
            }

            retVal = Regex.Replace(retVal, "[;\\/:*?\"...,%+–<>()!“”|‘’&']", "");
            retVal = retVal.Replace("[", "").Replace("]", "").Replace(" ", "-").Replace("…", "");
            return retVal.Replace("---", "-").Replace("--", "-").ToLower();
        }

        public static string GeneraLink(string strTitle, int zoneId, int id)
        {
            return "/" + UnicodeToKoDau(strTitle) + "-" + ((zoneId.ToString() == "4") ? "v-" : "") + id.ToString() + ".html";
        }

        public static string GeneraFeatureLink(string strTitle, string id)
        {
            return "/chu-de-nong/" + UnicodeToKoDau(strTitle) + "-" + id + ".html";
        }

        public static string ConvertDisplay(string intNum)
        {
            int intValue = int.Parse(intNum);
            string strResult = intValue.ToString("N0");
            if (strResult.Contains(','))
                strResult = strResult.Replace(',', '.');
            return strResult;
        }

        public static string DisplayTag(string strTag)
        {
            string strResult = string.Empty;
            if (!string.IsNullOrEmpty(strTag))
            {
                strTag = strTag.Split(',').First();
                strResult = UnicodeToKoDau(strTag) + ".html";

            }
            return strResult;
        }

        public static string RemoveHTML(string strHTML)
        {
            if (strHTML != null)
            {
                string strResult = Regex.Replace(strHTML, "<(.|\n)*?>", "");
                strResult = strResult.Replace("\n", "").Replace("\r", "").Replace("'", "");
                return HttpUtility.HtmlEncode(strResult);
            }
            else
            {
                return "";
            }
        }

        public static string ReturnUnicodeZoneName(int id)
        {
            string strResult = string.Empty;
            switch (id)
            {
                case 4:
                    strResult = "Video";
                    break;
                case 6:
                    strResult = "Đời";
                    break;
                case 2:
                    strResult = "Sao";
                    break;
                case 7:
                    strResult = "Trẻ";
                    break;
                case 9:
                    strResult = "Đẹp";
                    break;
                case 8:
                    strResult = "Chơi";
                    break;
                case 11:
                    strResult = "Đỉnh";
                    break;
                case 1:
                    strResult = "Mlog";
                    break;
            }
            return strResult;
        }

        public static string ReturnZoneName(int id)
        {
            string strResult = string.Empty;
            switch (id)
            {
                case 4:
                    strResult = "video";
                    break;
                case 6:
                    strResult = "doi";
                    break;
                case 2:
                    strResult = "sao";
                    break;
                case 7:
                    strResult = "tre";
                    break;
                case 9:
                    strResult = "dep";
                    break;
                case 8:
                    strResult = "choi";
                    break;
                case 11:
                    strResult = "dinh";
                    break;
                case 1:
                    strResult = "mlog";
                    break;
            }
            return strResult;
        }

        public static string ReturnCatName(int id)
        {
            string strResult = string.Empty;
            switch (id)
            {
                case 4:
                    strResult = "showbiz-360";
                    break;
                case 5:
                    strResult = "yan-show";
                    break;
                case 6:
                    strResult = "mchannel";
                    break;
                case 7:
                    strResult = "cam-nang-giai-tri";
                    break;
                case 1:
                    strResult = "sao-viet";
                    break;
                case 2:
                    strResult = "sao-dong";
                    break;
                case 3:
                    strResult = "sao-tay";
                    break;
                case 18:
                    strResult = "xa-hoi";
                    break;
                case 19:
                    strResult = "song-dep";
                    break;
                case 20:
                    strResult = "phap-dinh";
                    break;
                case 21:
                    strResult = "hoc-duong";
                    break;
                case 22:
                    strResult = "yeu";
                    break;
                case 23:
                    strResult = "cong-dong-mang";
                    break;
                case 24:
                    strResult = "du-lich";
                    break;
                case 25:
                    strResult = "am-thuc";
                    break;
                case 26:
                    strResult = "diem-hen";
                    break;
                case 27:
                    strResult = "thoi-trang";
                    break;
                case 28:
                    strResult = "trang-diem";
                    break;
                case 29:
                    strResult = "tips";
                    break;
                case 30:
                    strResult = "game";
                    break;
                case 31:
                    strResult = "cong-nghe";
                    break;
                case 32:
                    strResult = "the-thao";
                    break;
                case 8:
                    strResult = "bai-viet";
                    break;
                case 9:
                    strResult = "hinh-anh";
                    break;
                case 10:
                    strResult = "video";
                    break;
            }
            return strResult;
        }

        public static string ReturnUnicodeCatName(int id)
        {
            string strResult = string.Empty;
            switch (id)
            {
                case 4:
                    strResult = "Showbiz 360";
                    break;
                case 5:
                    strResult = "Yan Show";
                    break;
                case 6:
                    strResult = "Mchannel";
                    break;
                case 7:
                    strResult = "Cẩm Nang Giải Trí";
                    break;
                case 1:
                    strResult = "sao-viet";
                    break;
                case 2:
                    strResult = "sao-dong";
                    break;
                case 3:
                    strResult = "sao-tay";
                    break;
                case 18:
                    strResult = "xa-hoi";
                    break;
                case 19:
                    strResult = "song-dep";
                    break;
                case 20:
                    strResult = "phap-dinh";
                    break;
                case 21:
                    strResult = "hoc-duong";
                    break;
                case 22:
                    strResult = "yeu";
                    break;
                case 23:
                    strResult = "cong-dong-mang";
                    break;
                case 24:
                    strResult = "du-lich";
                    break;
                case 25:
                    strResult = "am-thuc";
                    break;
                case 26:
                    strResult = "diem-hen";
                    break;
                case 27:
                    strResult = "thoi-trang";
                    break;
                case 28:
                    strResult = "trang-diem";
                    break;
                case 30:
                    strResult = "game";
                    break;
                case 31:
                    strResult = "cong-nghe";
                    break;
                case 32:
                    strResult = "the-thao";
                    break;
                case 8:
                    strResult = "bai-viet";
                    break;
                case 9:
                    strResult = "hinh-anh";
                    break;
                case 10:
                    strResult = "video";
                    break;
            }
            return strResult;
        }
    }
}